package com.jameskarl.amap.map

import android.content.res.Resources
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.TypeReference

interface IJsonEntity

inline fun <reified T : IJsonEntity> String?.parseObject(): T? = try {
    if (this == null) null else JSON.parseObject(this, object : TypeReference<T>() {})
} catch (t: Throwable) {
    t.printStackTrace()
    null
}

fun Any.toJson(): String = JSON.toJSONString(this)


val Double.dp: Float                 // [xxhdpi](360 -> 1080)
    get() = android.util.TypedValue.applyDimension(
            android.util.TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics)

val Float.dp: Float                 // [xxhdpi](360 -> 1080)
    get() = android.util.TypedValue.applyDimension(
            android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics)

val Int.dp: Int
    get() = android.util.TypedValue.applyDimension(
            android.util.TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt()
